$(function(){

var supports = (function() {
    var div = document.createElement('div'),
        vendors = 'Khtml O Moz Webkit'.split(''),
        len = vendors.length;
    return function(prop) {
        if ( prop in div.style ) return true;
        if ('-ms-' + prop in div.style) return true;
        prop = prop.replace(/^[a-z]/, function(val) {
            return val.toUpperCase();
        });
        while(len--) {
            if ( vendors[len] + prop in div.style ) {
                return true;
            }
        }
    return false;
    };
})();


var scrollImg = {
        options: {
            container: "#smSlider",
            item: ".ui_slider_item",
            trigger: ".ui_slider_trigger",
            time: 2000
        },
        cur: 0,
        init: function(){
            var self = this;
            self.auto();
            $(self.options.trigger).on("hover", function(){
                var cur = $(this).index();
                setTimeout(function(){
                    self.scroll(cur);
                },100)

            });

        },
        auto: function(){
            var self = this, sv;
            function play(){
                sv = setInterval(function(){self.scroll();self.cur++;}, self.options.time);
            }
            setTimeout(function(){
                self.scroll();
                self.cur++;
            },500);

            play();

            $(self.options.container).hover(function(){
                clearInterval(sv);
                sv = null;
            }, function(){
                play();
            });

        },
        scroll: function(current){
            var self = this,
                opts = self.options,
                len = $(opts.container).find(opts.item).length,
                item = $(opts.container).find(opts.item),
                trigger = $(opts.container).find(opts.trigger);
            self.cur = (current !== undefined) ? current : self.cur;
            item.removeClass("current");
            trigger.removeClass("curr");
            item.eq(self.cur).addClass("current");
            trigger.eq(self.cur).addClass("curr");
            if(self.cur == (len-1)) self.cur = -1;

        },
        animate: function(){

        }
}

var mouseFllow = {
    container: ".zgwctop", //上方的大盒子
    box: ".zgwctop_xsd", //上方的 图
    trigger: ".trig",    //上方的文字
    bbox: ".zhwcboul",
    init: function(){
        var self = this,
            node = $(self.container).find(self.trigger);

        node.on("mouseenter", function(e){
            var x = $(this)[0].getBoundingClientRect().left,
                y = $(this)[0].getBoundingClientRect().top,
                cx = $(self.container)[0].getBoundingClientRect().left,
                cy = $(self.container)[0].getBoundingClientRect().top;

            var l = x-cx-13,
                t = y-cy-80,
                url = $(this).data("img");
            $(self.box).css({"left":l, "top":t}).find("img").attr("src",url);
        });
        
    }
}

var accordion = {
    options: {
        container: ".xylsbox",
        trigger: ".cls"
    },
    init: function(){
        var self = this,
            opts = self.options,
            trigger = $(opts.container).find(opts.trigger),
            item = trigger.parent(),
            triggerWidth = trigger.width(),
            itemWidth = item.width();

        trigger.on("click", function(){
            var p = $(this).parent();
            p.siblings().removeClass("current");
            p.addClass("current");
            p.prev().find(".tbb").removeClass("arrl");
            p.next().find(".tbb").addClass("arrl");
        });


    }
}

var addCart = {
    btn: "a[data-skuCode]",//".btn-buy a",
    init: function(){
        var self = this;
        $(self.btn).on("click", function(e){
            e.preventDefault();
            var sku = $(this).attr("data-skuCode");
           $.ajax({
                url: window.cart + '/cart/addsku.html',
                data: {
                    skuCode: sku
                },
                dataType: "jsonp",
                success: function(json){
                    if(json.success){
                        // 跟踪代码
                      _adwq.push([ '_setDataType','cart' ]);
                      _adwq.push([ '_setCustomer', (window.UID ? window.UID : window.UUID)]);
                      _adwq.push(['_setItem',
                          json.data.list.skuCode,
                          json.data.list.skuName,
                          json.data.list.skuPrice,
                          json.data.list.skuCount,
                          json.data.list.categoryCode || '',
                          json.data.list.categoryName || ''
                      ]);
                      _adwq.push([ '_trackTrans' ]);
                      // 跟踪代码结束
                        window.location.href = window.cart + '/cart/addskutocart.html';
                    } else {
                        alert(json.message);
                    }
                }
           });
        });
    }
}

accordion.init();
// mouseFllow.init();
scrollImg.init();
// addCart.init();

// $(".zghwc").tabchange({"onClass":"curr"});
// $(".sjhwc").tabchange({"onClass":"zuq1"});



});